﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@model Skoruba.IdentityServer4.Admin.BusinessLogic.Identity.Dtos.Identity.Interfaces.IUserClaimsDto
@inject IViewLocalizer Localizer

@{
	ViewBag.Title = Localizer["PageTitle"];
	Layout = "_Layout";
}

<form id="user-claims-form" asp-controller="Identity" asp-action="UserClaims" Method="post">
	<div class="row">
		
		<div class="col-12">
			<nav aria-label="breadcrumb">
				<ol class="breadcrumb">
					<li class="breadcrumb-item"><a asp-controller="Identity" asp-action="Users">@Localizer["NavigationUsers"]</a></li>
					<li class="breadcrumb-item"><a asp-controller="Identity" asp-action="UserProfile" asp-route-id="@Model.UserId">@Model.UserName</a></li>
					<li class="breadcrumb-item active" aria-current="page">@Localizer["PageTitle"]</li>
				</ol>
			</nav>
		</div>

		<div class="col-md-12">
			<h3>@Localizer["PageTitle"]</h3>

			<div asp-validation-summary="All" class="text-danger"></div>

			<!--Hidden -->
			<input type="hidden" asp-for="UserId"/>

			<div class="card mt-3">
				<h5 class="card-header">@Localizer["PanelTitleNew"]</h5>
				<div class="card-body">

					<!--Select with tags-->
					<div class="form-group row">
						<label asp-for="ClaimType" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("User/Section/Label", "Type")
						</label>
						<div class="col-sm-9">
							<picker id="ClaimType" multiple-select="false" min-search-text="2"
							        selected-item="@Model.ClaimType" url="@Url.Action("SearchClaims", "Configuration")?claim"
							        search-input-placeholder="@Localizer["PickerSearchItemPlaceholder"].Value"
							        selected-items-title="@Localizer["PickerSelectedItemsTitle"].Value" 
							        search-result-title="@Localizer["PickerSearchResultTitle"].Value"
							        suggested-items-title="@Localizer["PickerSuggestedItemsTitle"].Value" 
							        no-item-selected-title="@Localizer["PickerNoItemSelectedTitle"].Value" 
							        show-all-items-title="@Localizer["PickerShowAllItemsTitle"].Value"
							        item-already-selected-title="@Localizer["PickerItemAlreadySelectedTitle"].Value"
							        required="true" required-message="@Localizer["PickerRequiredMessage"].Value">
							</picker>

							<span asp-validation-for="ClaimType" class="text-danger"></span>
						</div>
					</div>

					<!--Input - text -->
					<div class="form-group row">
						<label asp-for="ClaimValue" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("User/Section/Label", "Value")
						</label>
						<div class="col-sm-9">
							<input type="text" required class="form-control" asp-for="ClaimValue">
							<span asp-validation-for="ClaimValue" class="text-danger"></span>
						</div>
					</div>

					<!--Button-->
					<div class="form-group row">
						<label class="col-sm-3 col-form-label">
						</label>
						<div class="col-sm-9">
							<button type="submit" id="user-claims-button" class="btn btn-primary">@Localizer["ButtonAddClaim"]</button>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>
</form>

<div class="row">
	<div class="col-md-12">
		<div class="card mt-3">
			<h5 class="card-header">@Localizer["PanelTitle"]</h5>
			<div class="card-body">

				<div class="row table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>@Localizer["TableType"]</th>
								<th>@Localizer["TableValue"]</th>
								<th></th>
							</tr>
						</thead>
						<tbody>
							@foreach (var client in Model.Claims)
							{
								<tr>
									<td>@client.ClaimType</td>
									<td>@client.ClaimValue</td>
									<td><a asp-action="UserClaimsDelete" asp-route-claimId="@client.ClaimId" asp-route-id="@Model.UserId" class="btn btn-danger">@Localizer["TableButtonRemove"]</a></td>
								</tr>
							}
						</tbody>
					</table>
				</div>
				<div class="row">
					<div class="col-12">
						@await Html.PartialAsync("Common/Pager", new Pager {Action = "UserClaims", PageSize = Model.PageSize, TotalCount = Model.TotalCount})
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

@section scripts
	{
	<script>
		$(function () {
			//Disable enter for this form
			FormMvc.disableEnter($('#user-claims-form'));

			//Allow validate hidden field
			FormMvc.allowValidateHiddenField($('#user-claims-form'));
		});
	</script>
}